package com.yoyosys.db.partition.vo;

import com.alibaba.fastjson.JSON;
import com.yoyosys.db.partition.constant.DBType;
import lombok.Data;

/**
 * SQL执行请求
 */
@Data
public class SqlReq {
    private String dbType;
    /**
     * jdbc连接串
     */
    private String jdbcUrl;
    /**
     * jdbc 用户名
     */
    private String username;
    /**
     * jdbc 密码
     */
    private String password;
    /**
     * jdbc 驱动类
     */
    private String driverClass;
    /**
     * jdbc schema
     */
    private String schemaName;
    /**
     * jdbc 表名
     */
    private String tableName;
    /**
     * sql查询语句，分页查询的时候需要带上占位符 ${pageStart} ${pageSize}
     */
    private String sql;

    /**
     * sql 总数统计语句
     */
    private String countSql;

    /**
     * 每页数据大小
     */
    private Integer pageSize = 1000;

    private Boolean needRet = false;


    public String toString(){
        return JSON.toJSONString(this);
    }

    public boolean getNeedRet(){
        if(needRet == null){
            return false;
        }
        return needRet.booleanValue();
    }


    public DBType getDbTypeEnum(){
        for (DBType type : DBType.values()) {
            if (type.name().equals(this.dbType)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown DBType : " + dbType);
    }
}
